<?php

/**
 * @file classes/journal/CTKTDAO.inc.php
 *
 * Copyright (c) 2003-2012 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class CTKTDAO
 * @ingroup journal
 * @see CTKT
 *
 * @brief Operations for retrieving and modifying CTKT objects.
 */

// $Id$
import ( 'classes.acct.CTKT' );
class CTKTDAO extends DAO {
	var $cache;
	function _cacheMiss(&$cache, $id) {
		$CTKT = & $this->getCTKT ( $id, null, false );
		$cache->setCache ( $id, $CTKT );
		return $CTKT;
	}
	function &_getCache() {
		if (! isset ( $this->cache )) {
			$cacheManager = & CacheManager::getManager ();
			$this->cache = & $cacheManager->getObjectCache ( 'CTKT', 0, array (
					&$this,
					'_cacheMiss' 
			) );
		}
		return $this->cache;
	}

	function &getCTKT_BC1($nam, $ngay1, $ngay2, $tk, $noco, $searchType = null, $search = null, $searchMatch = null) {
		$ngay1 = date ( 'Y-m-d', $ngay1 );
		$ngay2 = date ( 'Y-m-d', $ngay2 );
		
		$query = "SELECT a.soct, a.ngct, b.diengiai, a.mant, a.tigia, a.TK , a.macttk , b.tkdu , b.macttkdu, b.sotiennt AS psnont, b.sotiennt AS pscont, b.sotienvn AS psno, b.sotienvn AS psco, b.macttkdu AS madt, a.mact, a.noco FROM CTKT" . $nam . " a LEFT JOIN ctktdt" . $nam . " b ON (a.idphieu = b.idphieu) ";
		
		$query = $query . "WHERE DATE( a.ngct ) >= '" . $ngay1 . "' && DATE( a.ngct ) <=  '" . $ngay2 . "' && a.TK like '" . $tk . "%'";
		$query = $query . " && a.noco = '". $noco ."'" ;

		$query = $query . "		&& (b.sotienvn+ b.sotiennt) > 0  ORDER BY ngct, soct";

		//echo "$query ";
		$result = & $this->retrieve ( $query );
		
		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKT_BC1_FromRow' );
		
		$sections = $returner;
		$i = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {
			
			$sections [$i] ['ngct'] = $section->getngct ();
			$sections [$i] ['soct'] = $section->getsoct ();
			$sections [$i] ['diengiai'] = $section->getdiengiai ();
			$sections [$i] ['noco'] = $section->getnoco ();
			$sections [$i] ['tkdu'] = $section->gettkdu ();
			$sections [$i] ['tk'] = $section->gettk();
			$sections [$i] ['sotienvn'] = $section->getsotienvn ();
						
			
			$i += 1;
			unset ( $section );
		}
		return $sections;
	}

	function &getCTKT_view($query, $paramArray) {
		$result = & $this->retrieve ( $query, $paramArray );

		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKT_view_FromRow' );
		
		$sections = $returner;
		$i = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {
			$sections [$i] ['idphieu'] = $section->getidphieu ();
			$sections [$i] ['ngct'] = $section->getngct ();
			$sections [$i] ['soct'] = $section->getsoct ();
			$sections [$i] ['diengiai'] = $section->getdiengiai ();
			$sections [$i] ['noco'] = $section->getnoco ();
			$sections [$i] ['tkdu'] = $section->gettkdu ();
			$sections [$i] ['macttkdu'] = $section->getmacttkdu ();
			$sections [$i] ['tk'] = $section->gettk();
			$sections [$i] ['sotienvn'] = $section->getsotienvn ();
			$i += 1;
			unset ( $section );
		}
		return $sections;
	}


	function &getCTKT_edit($query) {
		$result = & $this->retrieve( $query );
		
		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKT_edit_FromRow' );
		
		$sections = $returner;
		$i = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {
			$sections [$i] ['idphieu'] = $section->getidphieu ();	$sections [$i] ['ngct'] = $section->getngct ();
			$sections [$i] ['soct'] = $section->getsoct ();
			$sections [$i] ['diengiai'] = $section->getdiengiai ();
			$sections [$i] ['hoten'] = $section->gethoten ();
			$sections [$i] ['diachi'] = $section->getdiachi ();
			$sections [$i] ['lydo'] = $section->getlydo ();
			$sections [$i] ['solgctg'] = $section->getsolgctg ();
			$sections [$i] ['mant'] = $section->getmant ();
			$sections [$i] ['tigia'] = $section->gettigia ();
			$sections [$i] ['noco'] = $section->getnoco ();
			$sections [$i] ['tkdu'] = $section->gettkdu ();
			$sections [$i] ['macttkdu'] = $section->getmacttkdu ();
			$sections [$i] ['tk'] = $section->gettk();
			$sections [$i] ['sotienvn'] = $section->getsotienvn ();


			a.hoten, a.diachi, a.lydo, a.solgctg, b.diengiai, a.mant, a.tigia,

			$i += 1;
			unset ( $section );
		}
		return $sections;
	}


	function &_returnCTKT_FromRow(&$row) {
		$CTKT = new CTKT ();
		$CTKT ->setidphieu($idphieu);
		$CTKT->setsoct($soct);
		$CTKT->setngct($ngct);
		$CTKT->setdiengiai($diengiai);
		$CTKT->setnoco($noco);
		$CTKT->settk($tk);
		$CTKT->settkdu($tkdu);
		$CTKT->setmacttkdu($macttkdu);
		$CTKT->setsotienvn($sotienvn);

		return $CTKT;
	}


	function &_returnCTKT_view_FromRow(&$row) {
		$CTKT = new CTKT();
		$CTKT ->setidphieu($idphieu);
		$CTKT->setsoct($soct);
		$CTKT->setngct($ngct);
		$CTKT->setdiengiai($diengiai);
		$CTKT->settk($tk);
		$CTKT->settkdu($tkdu);
		$CTKT->setmacttkdu($macttkdu);
		$CTKT->setsotienvn($sotienvn);
		return $CTKT;
	}


	function &_returnCTKT_BC1_FromRow(&$row) {
		$CTKT = new CTKT();
			//		( $row ['idphieu'],  $row ['ngct'], $row ['noco'], $row ['soct'],$row ['diengiai'],$row ['tk'], $row ['tkdu'], $row ['macttkdu'], $row ['sotienvn']);
		return $CTKT;
	}

	function &_returnCTKT_edit_FromRow(&$row) {
		//$CTKT = new CTKT ( $row ['idphieu'],  $row ['ngct'], $row ['noco'], $row ['soct'],$row ['diengiai'],$row ['tk'], $row ['tkdu'], $row ['macttkdu'], $row ['sotienvn']);
		//return $CTKT;
		$CTKT = new CTKT();
		return $CTKT;
	}

	
	/*
	 * Retrieve a CTKT by abbreviation.
	 * 
	 * @param $CTKTAbbrev string        	
	 * @param $locale string
	 *        	optional
	 * @return CTKT
	 */
	function &getCTKTByAbbrev($CTKTAbbrev, $journalId, $locale = null) {
		$sql = 'SELECT s.* FROM CTKT s, CTKT_settings l WHERE l.CTKT_id = s.CTKT_id AND l.setting_name = ? AND l.setting_value = ? AND s.journal_id = ?';
		$params = array (
				'abbrev',
				$CTKTAbbrev,
				$journalId 
		);
		if ($locale !== null) {
			$sql .= ' AND l.locale = ?';
			$params [] = $locale;
		}
		
		$result = & $this->retrieve ( $sql, $params );
		
		$returner = null;
		if ($result->RecordCount () != 0) {
			$returner = & $this->_returnCTKTFromRow ( $result->GetRowAssoc ( false ) );
		}
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Retrieve a CTKT by title.
	 * 
	 * @param $CTKTTitle string        	
	 * @return CTKT
	 */
	function &getCTKTByTitle($CTKTTitle, $journalId, $locale = null) {
		$sql = 'SELECT s.* FROM CTKT s, CTKT_settings l WHERE l.CTKT_id = s.CTKT_id AND l.setting_name = ? AND l.setting_value = ? AND s.journal_id = ?';
		$params = array (
				'title',
				$CTKTTitle,
				$journalId 
		);
		if ($locale !== null) {
			$sql .= ' AND l.locale = ?';
			$params [] = $locale;
		}
		
		$result = & $this->retrieve ( $sql, $params );
		
		$returner = null;
		if ($result->RecordCount () != 0) {
			$returner = & $this->_returnCTKTFromRow ( $result->GetRowAssoc ( false ) );
		}
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Retrieve a CTKT by title and abbrev.
	 * 
	 * @param $CTKTTitle string        	
	 * @param $CTKTAbbrev string        	
	 * @param $locale string
	 *        	optional
	 * @return CTKT
	 */
	function &getCTKTByTitleAndAbbrev($CTKTTitle, $CTKTAbbrev, $journalId, $locale) {
		$sql = 'SELECT s.* FROM CTKT s, CTKT_settings l1, CTKT_settings l2 WHERE l1.CTKT_id = s.CTKT_id AND l2.CTKT_id = s.CTKT_id AND l1.setting_name = ? AND l2.setting_name = ? AND l1.setting_value = ? AND l2.setting_value = ? AND s.journal_id = ?';
		$params = array (
				'title',
				'abbrev',
				$CTKTTitle,
				$CTKTAbbrev,
				$journalId 
		);
		if ($locale !== null) {
			$sql .= ' AND l1.locale = ? AND l2.locale = ?';
			$params [] = $locale;
			$params [] = $locale;
		}
		
		$result = & $this->retrieve ( $sql, $params );
		
		$returner = null;
		if ($result->RecordCount () != 0) {
			$returner = & $this->_returnCTKTFromRow ( $result->GetRowAssoc ( false ) );
		}
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Internal function to return a CTKT object from a row.
	 * 
	 * @param $row array        	
	 * @return CTKT
	 */
	
	/**
	 * Get the list of fields for which data can be localized.
	 * 
	 * @return array
	 */
	function getLocaleFieldNames() {
		return array (
				'title',
				'abbrev',
				'policy',
				'identifyType' 
		);
	}
	
	/**
	 * Update the localized fields for this table
	 * 
	 * @param $CTKT object        	
	 */
	function updateLocaleFields(&$CTKT) {
		$this->updateDataObjectSettings ( 'CTKT_settings', $CTKT, array (
				'CTKT_id' => $CTKT->getId () 
		) );
	}
	
	/**
	 * Insert a new CTKT.
	 * 
	 * @param $CTKT CTKT        	
	 */
	function insertCTKT(&$CTKT) {
		$this->update ( 'INSERT INTO CTKT
				(journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, hide_about, disable_comments, abstract_word_count)
				VALUES
				(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array (
				$CTKT->getJournalId (),
				$CTKT->getReviewFormId (),
				$CTKT->getSequence () == null ? 0 : $CTKT->getSequence (),
				$CTKT->getMetaIndexed () ? 1 : 0,
				$CTKT->getMetaReviewed () ? 1 : 0,
				$CTKT->getAbstractsNotRequired () ? 1 : 0,
				$CTKT->getEditorRestricted () ? 1 : 0,
				$CTKT->getHideTitle () ? 1 : 0,
				$CTKT->getHideAuthor () ? 1 : 0,
				$CTKT->getHideAbout () ? 1 : 0,
				$CTKT->getDisableComments () ? 1 : 0,
				( int ) $CTKT->getAbstractWordCount () 
		) );
		
		$CTKT->setId ( $this->getInsertCTKTId () );
		$this->updateLocaleFields ( $CTKT );
		return $CTKT->getId ();
	}
	
	/**
	 * Update an existing CTKT.
	 * 
	 * @param $CTKT CTKT        	
	 */
	function updateCTKT(&$CTKT) {
		$returner = $this->update ( 'UPDATE CTKT
				SET
					review_form_id = ?,
					seq = ?,
					meta_indexed = ?,
					meta_reviewed = ?,
					abstracts_not_required = ?,
					editor_restricted = ?,
					hide_title = ?,
					hide_author = ?,
					hide_about = ?,
					disable_comments = ?,
					abstract_word_count = ?
				WHERE CTKT_id = ?', array (
				$CTKT->getReviewFormId (),
				$CTKT->getSequence (),
				$CTKT->getMetaIndexed (),
				$CTKT->getMetaReviewed (),
				$CTKT->getAbstractsNotRequired (),
				$CTKT->getEditorRestricted (),
				$CTKT->getHideTitle (),
				$CTKT->getHideAuthor (),
				$CTKT->getHideAbout (),
				$CTKT->getDisableComments (),
				$this->nullOrInt ( $CTKT->getAbstractWordCount () ),
				$CTKT->getId () 
		) );
		$this->updateLocaleFields ( $CTKT );
		return $returner;
	}
	
	/**
	 * Delete a CTKT.
	 * 
	 * @param $CTKT CTKT        	
	 */
	function deleteCTKT(&$CTKT) {
		return $this->deleteCTKTById ( $CTKT->getId (), $CTKT->getJournalId () );
	}
	
	/**
	 * Delete a CTKT by ID.
	 * 
	 * @param $CTKTId int        	
	 * @param $journalId int
	 *        	optional
	 */
	function deleteCTKTById($CTKTId, $journalId = null) {
		$CTKTEditorsDao = & DAORegistry::getDAO ( 'CTKTEditorsDAO' );
		$CTKTEditorsDao->deleteEditorsByCTKTId ( $CTKTId, $journalId );
		
		// Remove articles from this CTKT
		$articleDao = & DAORegistry::getDAO ( 'ArticleDAO' );
		$articleDao->removeArticlesFromCTKT ( $CTKTId );
		
		// Delete published article entries from this CTKT -- they must
		// be re-published.
		$publishedArticleDao = & DAORegistry::getDAO ( 'PublishedArticleDAO' );
		$publishedArticleDao->deletePublishedArticlesByCTKTId ( $CTKTId );
		
		if (isset ( $journalId ) && ! $this->CTKTExists ( $CTKTId, $journalId ))
			return false;
		$this->update ( 'DELETE FROM CTKT_settings WHERE CTKT_id = ?', array (
				$CTKTId 
		) );
		return $this->update ( 'DELETE FROM CTKT WHERE CTKT_id = ?', array (
				$CTKTId 
		) );
	}
	
	/**
	 * Delete CTKT by journal ID
	 * NOTE: This does not delete dependent entries EXCEPT from CTKT_editors.
	 * It is intended
	 * to be called only when deleting a journal.
	 * 
	 * @param $journalId int        	
	 */
	function deleteCTKTByJournal($journalId) {
		$CTKT = & $this->getJournalCTKT ( $journalId );
		while ( ($CTKT = & $CTKT->next ()) ) {
			$this->deleteCTKT ( $CTKT );
			unset ( $CTKT );
		}
	}
	
	/**
	 * Retrieve an array associating all CTKT editor IDs with
	 * arrays containing the CTKT they edit.
	 * 
	 * @return array editorId => array(CTKT they edit)
	 */
	function &getEditorCTKT($journalId) {
		$returner = array ();
		
		$result = & $this->retrieve ( 'SELECT s.*, se.user_id AS editor_id FROM CTKT_editors se, CTKT s WHERE se.CTKT_id = s.CTKT_id AND s.journal_id = se.journal_id AND s.journal_id = ?', $journalId );
		
		while ( ! $result->EOF ) {
			$row = $result->GetRowAssoc ( false );
			$CTKT = & $this->_returnCTKTFromRow ( $row );
			if (! isset ( $returner [$row ['editor_id']] )) {
				$returner [$row ['editor_id']] = array (
						$CTKT 
				);
			} else {
				$returner [$row ['editor_id']] [] = $CTKT;
			}
			$result->moveNext ();
		}
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Retrieve all CTKT in which articles are currently published in
	 * the given issue.
	 * 
	 * @return array
	 */
	function &getCTKTForIssue($issueId) {
		$returner = array ();
		
		$result = & $this->retrieve ( 'SELECT DISTINCT s.*, COALESCE(o.seq, s.seq) AS CTKT_seq FROM CTKT s, published_articles pa, articles a LEFT JOIN custom_CTKT_orders o ON (a.CTKT_id = o.CTKT_id AND o.issue_id = ?) WHERE s.CTKT_id = a.CTKT_id AND pa.article_id = a.article_id AND pa.issue_id = ? ORDER BY CTKT_seq', array (
				$issueId,
				$issueId 
		) );
		
		while ( ! $result->EOF ) {
			$row = $result->GetRowAssoc ( false );
			$returner [] = & $this->_returnCTKTFromRow ( $row );
			$result->moveNext ();
		}
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Retrieve all CTKT for a journal.
	 * 
	 * @return DAOResultFactory containing CTKT ordered by sequence
	 */
	function &getJournalCTKT($journalId, $rangeInfo = null) {
		$result = & $this->retrieveRange ( 'SELECT * FROM CTKT WHERE journal_id = ? ORDER BY seq', $journalId, $rangeInfo );
		
		$returner = new DAOResultFactory ( $result, $this, '_returnCTKTFromRow' );
		return $returner;
	}
	
	/**
	 * Retrieve the IDs and titles of the CTKT for a journal in an associative array.
	 * 
	 * @return array
	 */
	function &getCTKTTitles($journalId, $submittableOnly = false) {
		$CTKT = array ();
		
		$CTKTIterator = & $this->getJournalCTKT ( $journalId );
		while ( ($CTKT = & $CTKTIterator->next ()) ) {
			if ($submittableOnly) {
				if (! $CTKT->getEditorRestricted ()) {
					$CTKT [$CTKT->getId ()] = $CTKT->getLocalizedTitle ();
				}
			} else {
				$CTKT [$CTKT->getId ()] = $CTKT->getLocalizedTitle ();
			}
			unset ( $CTKT );
		}
		
		return $CTKT;
	}
	
	/**
	 * Check if a CTKT exists with the specified ID.
	 * 
	 * @param $CTKTId int        	
	 * @param $journalId int        	
	 * @return boolean
	 */
	function CTKTExists($CTKTId, $journalId) {
		$result = & $this->retrieve ( 'SELECT COUNT(*) FROM CTKT WHERE CTKT_id = ? AND journal_id = ?', array (
				$CTKTId,
				$journalId 
		) );
		$returner = isset ( $result->fields [0] ) && $result->fields [0] == 1 ? true : false;
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Sequentially renumber CTKT in their sequence order.
	 * 
	 * @param $journalId int        	
	 */
	function resequenceCTKT($journalId) {
		$result = & $this->retrieve ( 'SELECT CTKT_id FROM CTKT WHERE journal_id = ? ORDER BY seq', $journalId );
		
		for($i = 1; ! $result->EOF; $i ++) {
			list ( $CTKTId ) = $result->fields;
			$this->update ( 'UPDATE CTKT SET seq = ? WHERE CTKT_id = ?', array (
					$i,
					$CTKTId 
			) );
			
			$result->moveNext ();
		}
		
		$result->close ();
		unset ( $result );
	}
	
	/**
	 * Get the ID of the last inserted CTKT.
	 * 
	 * @return int
	 */
	function getInsertCTKTId() {
		return $this->getInsertId ( 'CTKT', 'CTKT_id' );
	}
	
	/**
	 * Delete the custom ordering of an issue's CTKT.
	 * 
	 * @param $issueId int        	
	 */
	function deleteCustomCTKTOrdering($issueId) {
		return $this->update ( 'DELETE FROM custom_CTKT_orders WHERE issue_id = ?', $issueId );
	}
	
	/**
	 * Delete a CTKT from the custom CTKT order table.
	 * 
	 * @param $issueId int        	
	 * @param $CTKTId int        	
	 */
	function deleteCustomCTKT($issueId, $CTKTId) {
		$sequence = $this->getCustomCTKTOrder ( $issueId, $CTKTId );
		
		$this->update ( 'DELETE FROM custom_CTKT_orders WHERE issue_id = ? AND CTKT_id = ?', array (
				$issueId,
				$CTKTId 
		) );
		
		// Reduce the CTKT order of every successive CTKT by one
		$this->update ( 'UPDATE custom_CTKT_orders SET seq = seq - 1 WHERE issue_id = ? AND seq > ?', array (
				$issueId,
				$sequence 
		) );
	}
	
	/**
	 * Sequentially renumber custom CTKT orderings in their sequence order.
	 * 
	 * @param $issueId int        	
	 */
	function resequenceCustomCTKTOrders($issueId) {
		$result = & $this->retrieve ( 'SELECT CTKT_id FROM custom_CTKT_orders WHERE issue_id = ? ORDER BY seq', $issueId );
		
		for($i = 1; ! $result->EOF; $i ++) {
			list ( $CTKTId ) = $result->fields;
			$this->update ( 'UPDATE custom_CTKT_orders SET seq = ? WHERE CTKT_id = ? AND issue_id = ?', array (
					$i,
					$CTKTId,
					$issueId 
			) );
			
			$result->moveNext ();
		}
		
		$result->close ();
		unset ( $result );
	}
	
	/**
	 * Check if an issue has custom CTKT ordering.
	 * 
	 * @param $issueId int        	
	 * @return boolean
	 */
	function customCTKTOrderingExists($issueId) {
		$result = & $this->retrieve ( 'SELECT COUNT(*) FROM custom_CTKT_orders WHERE issue_id = ?', $issueId );
		$returner = isset ( $result->fields [0] ) && $result->fields [0] == 0 ? false : true;
		
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Get the custom CTKT order of a CTKT.
	 * 
	 * @param $issueId int        	
	 * @param $CTKTId int        	
	 * @return int
	 */
	function getCustomCTKTOrder($issueId, $CTKTId) {
		$result = & $this->retrieve ( 'SELECT seq FROM custom_CTKT_orders WHERE issue_id = ? AND CTKT_id = ?', array (
				$issueId,
				$CTKTId 
		) );
		
		$returner = null;
		if (! $result->EOF) {
			list ( $returner ) = $result->fields;
		}
		$result->Close ();
		unset ( $result );
		
		return $returner;
	}
	
	/**
	 * Import the current CTKT orders into the specified issue as custom
	 * issue orderings.
	 * 
	 * @param $issueId int        	
	 */
	function setDefaultCustomCTKTOrders($issueId) {
		$result = & $this->retrieve ( 'SELECT s.CTKT_id FROM CTKT s, issues i WHERE i.journal_id = s.journal_id AND i.issue_id = ? ORDER BY seq', $issueId );
		
		for($i = 1; ! $result->EOF; $i ++) {
			list ( $CTKTId ) = $result->fields;
			$this->insertCustomCTKTOrder ( $issueId, $CTKTId, $i );
			$result->moveNext ();
		}
		
		$result->close ();
		unset ( $result );
	}
	
	/**
	 * INTERNAL USE ONLY: Insert a custom CTKT ordering
	 * 
	 * @param $issueId int        	
	 * @param $CTKTId int        	
	 * @param $seq int        	
	 */
	function insertCustomCTKTOrder($issueId, $CTKTId, $seq) {
		$this->update ( 'INSERT INTO custom_CTKT_orders (CTKT_id, issue_id, seq) VALUES (?, ?, ?)', array (
				$CTKTId,
				$issueId,
				$seq 
		) );
	}
	
	/**
	 * Move a custom issue ordering up or down, resequencing as necessary.
	 * 
	 * @param $issueId int        	
	 * @param $CTKTId int        	
	 * @param $newPos int
	 *        	The new position (0-based) of this CTKT
	 * @param $up boolean
	 *        	Whether we're moving the CTKT up or down
	 */
	function moveCustomCTKTOrder($issueId, $CTKTId, $newPos, $up) {
		$this->update ( 'UPDATE custom_CTKT_orders SET seq = ? ' . ($up ? '-' : '+') . ' 0.5 WHERE issue_id = ? AND CTKT_id = ?', array (
				$newPos,
				$issueId,
				$CTKTId 
		) );
		$this->resequenceCustomCTKTOrders ( $issueId );
	}
}

?>
